package com.renge.eduservice.controller.homepage;

import com.renge.commonutils.R;
import com.renge.eduservice.entity.EduSubject;
import com.renge.eduservice.entity.json.SubjectJson;
import com.renge.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description="前端首页课程类别管理")
@RestController
@CrossOrigin
@RequestMapping("/eduservice/front-subject")
public class IndexFrontSubjectController {
    @Autowired
    private EduSubjectService service;
    @ApiOperation(value = "根据一级类型查询二级类型")
    @GetMapping("/parent/{parentId}")
    public R findAllByParentId(@ApiParam(name = "parentId",value = "一级类型",required = true)
                           @PathVariable("parentId")String parentId){

       List<EduSubject>subjectList=service.findAllByParentId(parentId);
        return R.ok().data("subjectList",subjectList);
    }
    @ApiOperation(value = "查询所有类别并封装返回")
    @GetMapping("/allSubject")
    public R findAllSubject(){
        List<SubjectJson>subjectList=service.findAllSubject();
        return R.ok().data("subjectList",subjectList);
    }

}
